/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dtn.getdata;

import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLEncoder;

import dtn.models.News;
import dtn.supports.Constant;

/**
 * 
 * @author asus
 */
public class NewsPreview {
	// public static string to set value of content

	private String title;
	private String imageUrl;
	private String url;
	private String hotContent;
	private String parentUrl;
	private String parentImageUrl;

	public NewsPreview() {
		title = imageUrl = url = hotContent = "";
		parentImageUrl = ConstantCompare.NewsPreview_Image_ParentUrl;
		parentUrl = ConstantCompare.NewsPreview_ParentUrl;
	}

	@Override
	public String toString() {
		return "\nTitle: " + getTitle() + "\nImage: " + getImageUrl()
				+ "\nUrl: " + getUrl() + "\nHotContent: " + getHotContent();
	}

	/**
	 * @return the Title
	 */
	public String getTitle() {
		return title;
	}

	/**
	 * @param Title
	 *            the Title to set
	 */
	public void setTitle(String Title) {
		this.title = Title;
	}

	/**
	 * @return the ImageUrl
	 */
	public String getImageUrl() {
		if (imageUrl.equals("")) {
			return imageUrl;
		} else {
			String urlStr = parentImageUrl
					+ imageUrl.substring(3, imageUrl.length());
			urlStr = urlStr.trim().replaceAll(" ", "%20");

			return urlStr;
		}
	}

	/**
	 * @param ImageUrl
	 *            the ImageUrl to set
	 */
	public void setImageUrl(String ImageUrl) {
		this.imageUrl = ImageUrl;
	}

	/**
	 * @return the Url
	 */
	public String getUrl() {
		if (url.equals("")) {
			return url;
		} else {
			return parentUrl + url;
		}
	}

	/**
	 * @param Url
	 *            the Url to set
	 */
	public void setUrl(String Url) {
		this.url = Url;
	}

	/**
	 * @return the HotContent
	 */
	public String getHotContent() {
		return hotContent;
	}

	/**
	 * @param HotContent
	 *            the HotContent to set
	 */
	public void setHotContent(String HotContent) {
		this.hotContent = HotContent;
	}

	/**
	 * @return the parentUrl
	 */
	public String getParentUrl() {
		return parentUrl;
	}

	/**
	 * @param parentUrl
	 *            the parentUrl to set
	 */
	public void setParentUrl(String parentUrl) {
		this.parentUrl = parentUrl;
	}

	/**
	 * 
	 * @return
	 */
	public News toNews() {
		int start_index = 0;
		int end_index = 0;
		String strID = "";

		this.url = this.url.trim();
		end_index = this.url.length();
		start_index = this.url.indexOf(ConstantCompare.News_ID);
		strID = this.url.substring(
				start_index + ConstantCompare.News_ID.length() + 1,
				end_index);
		
		return new News(strID, getTitle(), getHotContent(), getImageUrl(), getUrl(), "");
	}
}
